package com.itheima.controller;

import com.itheima.pojo.KsClass;
import com.itheima.pojo.R;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/login")
public class LoginController {
    @Autowired
    private UserService userService;

    @GetMapping("/{mobile}")
    public R findType(@PathVariable String mobile){
        List<KsClass> list = userService.findType(mobile);
        R r = new R();
        r.setCode(0);
        r.setErrorMessage("操作成功");
        r.setData(list);
        return r;
    }

    @PostMapping("/in")
    public R login(@RequestBody User user){
        User user1 =  userService.login(user);
      if(user1==null){
          R r = new R();
          r.setCode(1);
          r.setErrorMessage("操作失败");
          return r;
      }
        R r = new R();
        r.setCode(0);
        r.setErrorMessage("操作成功");
      return r;
    }
}
